import { apiResponse, axiosInstance } from './Index';

export interface RentingHouse {
  id: number
  type_id: string
  storage_time: string
  update_time: string
  city: string
  district: string
  source: string
  title: string
  image: string | null
  address: string | null
  rent_type: 'whole' | 'share'
  price: number
  square: number
}

export class RentingHouseAPI {
  public static list(search?: string, page?: number): Promise<{ count: number, list: RentingHouse[] }> {
    return new Promise<{ count: number, list: RentingHouse[] }>((resolve, reject) => {
      axiosInstance({
        method: 'GET',
        url: 'api/renting-house/list',
        params: {
          page,
          search
        }
      }).then(value => {
        const data: apiResponse = value.data as apiResponse
        resolve(data.data as { count: number, list: RentingHouse[] })
      }).catch(reject)
    })
  }
}
